﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Ewk.Extensions
{
    public static class StringExtensions
    {
        private static readonly Regex WordRegEx = new Regex(@"(\w+)\W*", RegexOptions.Compiled);

        public static bool IsNullOrEmpty(this String source)
        {
            return string.IsNullOrEmpty(source);
        }

        public static bool IsNullOrWhiteSpace(this String source)
        {
            return string.IsNullOrWhiteSpace(source);
        }

        public static bool IsNumeric(this String source)
        {
            return source
                .ToCharArray()
                .All(char.IsDigit);
        }

        public static IEnumerable<string> GetWords(this string content)
        {
            var words = new List<string>();

            var match = WordRegEx.Match(content);
            while (match.Success)
            {
                var word = match.Groups[1].Value.ToUpperInvariant();

                if (!word.IsNumeric())
                {
                    words.Add(word);
                }

                match = match.NextMatch();
            }

            return words;
        }
    }
}